package com.liantong.demo_part2.Service.Impl;

import com.liantong.demo_part2.Mapper.RankMapper;
import com.liantong.demo_part2.Service.RankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class RankServiceImpl implements RankService {

    @Autowired
    private RankMapper rankMapper;

    @Override
    public void zhijie_rank(String high_flow_weight,String high_meal_weight,String pingjing_weight){
        System.out.println(high_flow_weight+"   "+high_meal_weight+"    "+pingjing_weight);
        rankMapper.zhijie_rank( high_flow_weight, high_meal_weight, pingjing_weight);
        rankMapper.zhijie_index1();
        rankMapper.zhijie_index2();

    }

    @Override
    public void AHP_rank(String[] list) {
        rankMapper.AHP_rank1(list[0]);
        rankMapper.AHP_rank2(list[1]);
        rankMapper.AHP_rank3(list[2]);
        rankMapper.AHP_total();
        rankMapper.AHP_index1();
        rankMapper.AHP_index2();
    }

    @Override
    public void TOPSIS_rank_pre_cal() {
        TOPSIS_rank_pre();
        TOPSIS_rank_guiyi();
    }

    @Override
    public void TOPSIS_rank(String[] list) {

        Map<String,String> parms = new HashMap<>();
        for (int i = 0; i <list.length;i++){
            parms.put("weight"+(i+1),list[i]);
        }
        Map<String,String> max_and_min = rankMapper.get_min_and_max();
        parms.putAll(max_and_min);
        System.out.println(parms);
        rankMapper.TOPSIS_zheng_value(parms);
        rankMapper.TOPSIS_fu_value(parms);
        rankMapper.TOPSIS_total();
        rankMapper.TOPSIS_index1();
        rankMapper.TOPSIS_index2();
    }

    /**
     * TOPSIS法进行计算前应该先进行数据预处理
     */
    public void TOPSIS_rank_pre(){
        rankMapper.TOPSIS_duankou_pre();
        rankMapper.TOPSIS_zhishi_pre();
        String increase_min = rankMapper.TOPSIS_get_min_increase();
        System.out.println("min_increase "+increase_min);
        rankMapper.TOPSIS_liuliangzengzhang_pre(increase_min);
        rankMapper.TOPSIS_putonguser_pre();
        System.out.println("TOPSIS_rank_pre部分已完成");
    }

    /**
     * TOPSIS法归一化计算分值
     */
    public void TOPSIS_rank_guiyi(){

        rankMapper.TOPSIS_guiyi_duankou1(rankMapper.TOPSIS_guiyi_duankou1_sum());
        System.out.println(1);
        rankMapper.TOPSIS_guiyi_zhishi2(rankMapper.TOPSIS_guiyi_zhishi2_sum());
        System.out.println(2);
        rankMapper.TOPSIS_guiyi_putonguser3(rankMapper.TOPSIS_guiyi_putonguser3_sum());
        System.out.println(3);
        rankMapper.TOPSIS_guiyi_quanliang4(rankMapper.TOPSIS_guiyi_quanliang4_sum());
        System.out.println(4);
        rankMapper.TOPSIS_guiyi_junzhi5(rankMapper.TOPSIS_guiyi_junzhi5_sum());
        System.out.println(5);
        rankMapper.TOPSIS_guiyi_gaodenguser6(rankMapper.TOPSIS_guiyi_gaodenguser6_sum());
        System.out.println(6);
        rankMapper.TOPSIS_guiyi_liuliangzengzhang7(rankMapper.TOPSIS_guiyi_liuliangzengzhang7_sum());
        System.out.println(7);
        rankMapper.TOPSIS_guiyi_top10user8(rankMapper.TOPSIS_guiyi_top10user8_sum());
        System.out.println(8);
        rankMapper.TOPSIS_guiyi_fengzhi9(rankMapper.TOPSIS_guiyi_fengzhi9_sum());
        System.out.println("TOPSIS_rank_guiyi部分已完成");

    }
}
